<?php
if (!defined("_INDEX")) { header("Location: /"); die; }

require_once ADMIN.DS."/head.php";
?>
<h1>Выбрать компанию</h1><br />
<input type="text" placeholder="Поиск..." id="search" />
<br /><br />
<table cellpadding='0' cellspacing='0' class='list' id="table">
	<tr class='table_header'>
		<td width='50px'>ID</td>
		<td width='300px'>Название</td>
		<td width='100px' title="Уставной капитал | Активы | Прибыль">Записи</td>
		<td width='200px' class="actions">Действия</td>
	</tr><?php
		$query = "select `C`.*,count(distinct `CC`.`cc_id`) as `cc`,count(distinct `A`.`asset_id`) as `asset`
			from `companies` as `C`
			left join `charter_capital` as `CC` on `CC`.`company_id` = `C`.`company_id`
			left join `assets` as `A` on `A`.`company_id` = `C`.`company_id`
			where
				`C`.`city_id` = '".$current_admin_city['city_id']."' and
				`C`.`head_office` = '0'
			group by `C`.`company_id`
			order by `name`";
		$companies = $db->getTable($query);
		
		foreach ($companies as $company){
			echo "<tr class='tr'><td>$company[company_id]</td>";
			echo "<td class='find'>$company[name]</td>";
			$cc = $db->getCell("select count(distinct `profit_id`) from `profits` where `company_id` = '$company[company_id]'");
			echo "<td title='Уставной капитал | Активы | Прибыль'>$company[cc] | $company[asset] | $cc</td>";
			echo "<td class='actions'><a href='/admin/amount/edit/$company[company_id]' class='edit'>Редактировать</a> | <a href='/admin/amount/delete/$company[company_id]' class='delete'>Удалить все</a></td></tr>";
			echo "</tr>";
		}
?></table>

<?php require_once ADMIN.DS."/footer.php"; ?>